package org.xg.study.boot.common.logs;

import java.util.HashMap;

/**
 * @CLassName CodeBook
 * @description
 * @author cmg
 * @date 2021/7/28 10:24
 * @version 1.0
 **/
public class CodeBook extends HashMap<Integer, String> {
    private static final long serialVersionUID = 1595594900968581056L;
    private static CodeBook instance = null;

    private static final String ERRCODE = "[%s]";
    private static final String ERRTRANS = "can not translate \"%s\".";

    public static CodeBook I() {
        if (instance == null) {
            instance = new CodeBook();
        }
        return instance;
    }

    private CodeBook() {
        super();
    }

    /**
     * translate code
     *
     * @param code    code number
     * @param def_val default message
     * @param args    message arguments
     * @return translated message
     */
    public String translate(int code, String def_val, Object... args) {
        return String.format(ERRCODE, code) + String.format(def_val, args);
    }
}
